package com.qf.zyh.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.dao.ApiSystemparamMapper;
import com.qf.zyh.entity.ApiSystemparam;
import com.qf.zyh.services.SystemparatersServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemparatersServicesImpl implements SystemparatersServices {
    @Autowired
    private ApiSystemparamMapper apiSystemparamMapper;

    @Override
    public ResultType table(Integer page, Integer limit, String name, Integer state) {
        PageHelper.startPage(page,limit);
        List<ApiSystemparam> systemparams=apiSystemparamMapper.selectByName(name,state);
        PageInfo info = new PageInfo(systemparams);
        return new ResultType(0,"",(int)info.getTotal(),info.getList());
    }

    @Override
    public ResponseResult delApi(Integer[] ids) {
        apiSystemparamMapper.delApi(ids);
        return ResponseResult.getSuccess();
    }

    @Override
    public ResponseResult addApi(ApiSystemparam api) {
        int i = apiSystemparamMapper.insertSelective(api);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("出错惹");
    }

    @Override
    public ResponseResult updateApi(ApiSystemparam api) {
        int i = apiSystemparamMapper.updateByPrimaryKeySelective(api);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("出错啦");
    }
}
